<?php

/**
 * $servicios actions.
 *
 * @package    cronos-doctrine
 * @subpackage $servicios
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class gastosActions extends sfActions
{
    
  public function executeResumen(sfWebRequest $request)
  {
      
      $this->fecha = $request->getParameter('fecha');
      
      $empresa_egresos = new EmpresaEgresos();
      
      //Hace permanente la pagina en una variable de sesion
      if($request->getParameter('page')){
          $this->getUser()->setAttribute('page_empresa_egresos', $request->getParameter('page'));
      }
      
      $this->empresa_egresos = new sfDoctrinePager('EmpresaEgresos', sfConfig::get('app_x_pag'));
      $this->empresa_egresos->setQuery($empresa_egresos->getEmpresaEgresos($this->fecha));
      $this->empresa_egresos->setPage($this->getUser()->getAttribute('page_empresa_egresos'));
      $this->empresa_egresos->init();
      
      $this->form = new EmpresaEgresosForm();
      $this->form->setWidget('fecha', new sfWidgetFormInputHidden(array(),array('value' => $this->fecha)));
      
      
  }
  
  public function executeNew(sfWebRequest $request)
  {
      
      $camioneta = new Camioneta();
      $this->camioneta = $camioneta->getCamionetaGuardUser($this->getUser()->getGuardUser()->getId());
      $this->camioneta_id = $this->camioneta->getId();
    
    $this->form = new EmpresaEgresosForm();
    $this->form->setWidget('fecha', new sfWidgetFormInputHidden(array(), array('value' => date('Y-m-d'))));
    $this->form->setWidget('concepto_cf_id', new sfWidgetFormInputHidden(array(),array('value' => 1)));
    $this->form->setWidget('division_id', new sfWidgetFormInputHidden(array(),array('value' => 2)));
    $this->form->setWidget('operador_id', new sfWidgetFormInputHidden(array(),array('value' => $this->getUser()->getAttribute('agente_user'))));
    $this->form->setWidget('camioneta_id', new sfWidgetFormInputHidden(array(),array('value' => $this->camioneta_id)));
    $this->form->setWidget('categoria_id', new sfWidgetFormInputHidden(array(),array('value' => 1)));
    $this->form->setWidget('precio', new sfWidgetFormInput(array(),array('value' => $request->getParameter('categoria_id'),'style' => 'text-align: right')));
        
    
  }
  
  
   public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new EmpresaEgresosForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('resumen');
  }
  
    protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
       
      $empresa_egresos = $form->save();

      $this->redirect('dashboard/cierre');
      
    }
  }
  
    public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($empresa_egresos = Doctrine_Core::getTable('EmpresaEgresos')->find(array($request->getParameter('id'))), sprintf('Object ConceptoCf does not exist (%s).', $request->getParameter('id')));
    $empresa_egresos->delete();
    
    $this->redirect('dashboard/cierre');
    
  }
  
  
  
  
}
